package com.example.zcq.rxjava2retrofitmvp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.zcq.rxjava2retrofitmvp.R;
import com.example.zcq.rxjava2retrofitmvp.base.BaseActivity;
import com.example.zcq.rxjava2retrofitmvp.constant.Constant;
import com.example.zcq.rxjava2retrofitmvp.view.CustomDialog;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    /**
     * 跳转到Rxjava2activity
     */
    private Button mBtn1;
    private Button mBtn2;
    /**
     * 申请权限
     */
    private Button mBtn0;
    /**
     * 3跳转到查看联系人
     */
    private Button mBtn3;
    /**
     * 4跳转到
     */
    private Button mBtn4;
    /**
     * 5跳转到
     */
    private Button mBtn5;
    /**
     * 6跳转到
     */
    private Button mBtn6;
    /**
     * 7跳转到
     */
    private Button mBtn7;
    /**
     * 8跳转到
     */
    private Button mBtn8;
    /**
     * 9跳转到
     */
    private Button mBtn9;
    private CustomDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    private void initView() {
        mBtn1 = (Button) findViewById(R.id.btn1);
        mBtn2 = (Button) findViewById(R.id.btn2);
        mBtn1.setOnClickListener(this);
        mBtn2.setOnClickListener(this);
        mBtn0 = (Button) findViewById(R.id.btn0);
        mBtn0.setOnClickListener(this);
        mBtn3 = (Button) findViewById(R.id.btn3);
        mBtn3.setOnClickListener(this);
        mBtn4 = (Button) findViewById(R.id.btn4);
        mBtn4.setOnClickListener(this);
        mBtn5 = (Button) findViewById(R.id.btn5);
        mBtn5.setOnClickListener(this);
        mBtn6 = (Button) findViewById(R.id.btn6);
        mBtn6.setOnClickListener(this);
        mBtn7 = (Button) findViewById(R.id.btn7);
        mBtn7.setOnClickListener(this);
        mBtn8 = (Button) findViewById(R.id.btn8);
        mBtn8.setOnClickListener(this);
        mBtn9 = (Button) findViewById(R.id.btn9);
        mBtn9.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.btn1:
                startActivity(new Intent(MainActivity.this, Rxjava2RetrofitMvpActivity.class));
                break;
            case R.id.btn2:
                startActivity(new Intent(MainActivity.this, ShowPicActivity.class));
                break;
            case R.id.btn0:

                if (hasPermission(Constant.WRITE_READ_EXTERNAL_CAMERA_PERMISSION)) {
                    Toast.makeText(this, "权限都有", Toast.LENGTH_SHORT).show();

                } else {
                    requestPermission(Constant.WRITE_READ_EXTERNAL_CAMERA_CODE, Constant.WRITE_READ_EXTERNAL_CAMERA_PERMISSION);
                }
                break;
            case R.id.btn3:
                startActivity(new Intent(MainActivity.this, SeeContactsActivity.class));
                break;
            case R.id.btn4://dialog弹出
                CustomDialog.Builder builder=new CustomDialog.Builder(this);
                 dialog = builder.cancelTouchout(false)
                        .style(android.R.style.Theme_Holo_Dialog)
                        .view(R.layout.dialog_alert)
                        .heightdp(300)
                        .widthdp(320)
                        .addViewOnclick(R.id.tv_left, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                dialog.dismiss();
                            }
                        })
                        .build();
                dialog.show();
                break;
            case R.id.btn5:
                break;
            case R.id.btn6:
                break;
            case R.id.btn7:
                break;
            case R.id.btn8:
                break;
            case R.id.btn9:
                break;
        }
    }

    @Override
    public void douyou() {

        Toast.makeText(this, "权限已得", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void doWriteSDCard() {

        Toast.makeText(this, "申请到读写权限了", Toast.LENGTH_SHORT).show();
    }
}
